
 // 放大镜功能
//放大镜功能
function Zoom(){
    this.middle=document.querySelector('.middle')
    this.big=document.querySelector('.big')
    this.shade=document.querySelector('.shade')
    this.small=document.querySelector('.small')
    this.bigImg=document.querySelector('.big img')
    this.middleImg=document.querySelector('.middle>img')
}
Zoom.prototype.move=function(){
    //点击小图切换选框
    for(let i=0;i<this.small.children.length;i++){
        this.small.children[i].onclick=()=>{
            for(let j=0;j<this.small.children.length;j++){
                this.small.children[j].className=''
            }
            this.small.children[i].className='active'
            var path = this.small.children[i].firstElementChild.getAttribute('src')
            this.middleImg.setAttribute('src',path)
            this.bigImg.setAttribute('src',path)
        }            
    }
    //鼠标移动遮罩跟随
    this.middle.onmouseover=()=>{
        this.big.style.display='block'
        this.shade.style.display='block'
        this.middle.onmousemove=()=>{
            // 鼠标移入大图消失
            var e = window.event
            var x = e.pageX
            var y = e.pageY
            var l = x - this.shade.clientWidth/2-this.middle.offsetLeft
            var t = y - this.shade.clientHeight/2-this.middle.offsetTop
            //限制遮罩运动范围
            if(l<0) l=0
            if(t<0) t=0
            if(l>this.middle.offsetWidth-this.shade.offsetWidth) l=this.middle.offsetWidth-this.shade.offsetWidth
            if(t>this.middle.offsetHeight-this.shade.offsetHeight) t=this.middle.offsetHeight-this.shade.offsetHeight
            this.shade.style.top=t+'px'
            this.shade.style.left=l+'px'
            //鼠标移动大图大小跟随变化
            this.bigImg.style.left=-l/this.middle.offsetWidth*this.bigImg.offsetWidth+'px'
            this.bigImg.style.top=-t/this.middle.offsetHeight*this.bigImg.offsetHeight+'px'
        }
                //鼠标划出大图消失
        this.middle.onmouseout=()=>{
            this.shade.style.display='none'
            this.big.style.display='none'
        }
    }
}


// 商品扩展标题
$('.goods_extend_tit li').on('click',function(){
    $(this).siblings().removeClass('goods_extend_tit_active')
    $(this).attr('class','goods_extend_tit_active')
})


